<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加柜机</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f5f5f5;
            margin: 0;
            padding: 20px;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background-color: #fff;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        h2 {
            text-align: center;
            color: #333;
            border-bottom: 1px solid #eee;
            padding-bottom: 15px;
        }
        .form-group {
            margin-bottom: 20px;
            display: flex;
            align-items: center;
        }
        .form-group label {
            width: 120px;
            text-align: right;
            padding-right: 10px;
            font-weight: bold;
            color: #555;
        }
        .form-group.required label:after {
            content: " *";
            color: red;
        }
        .form-group input,
        .form-group select {
            flex: 1;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
        }
        .form-group select {
            height: 38px;
        }
        .form-group input:focus,
        .form-group select:focus {
            outline: none;
            border-color: #4CAF50;
            box-shadow: 0 0 5px rgba(76, 175, 80, 0.3);
        }
        .btn-group {
            text-align: center;
            margin-top: 30px;
        }
        .btn {
            padding: 10px 30px;
            margin: 0 10px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        .btn-primary {
            background-color: #4CAF50;
            color: white;
        }
        .btn-secondary {
            background-color: #ccc;
            color: #333;
        }
        .btn:hover {
            opacity: 0.9;
        }
        .region-selector {
            display: flex;
            flex: 1;
        }
        .region-selector select {
            flex: 1;
            margin-right: 10px;
        }
        .region-selector select:last-child {
            margin-right: 0;
        }
    </style>
</head>
<body>
<div class="container">
    <h2>添加柜机</h2>
    <form id="cabinetForm">
        <div class="form-group required">
            <label for="code">柜机编码</label>
            <input type="text" id="code" name="code" placeholder="请输入柜机编码" required>
        </div>

        <div class="form-group required">
            <label for="region">所在地区</label>
            <div class="region-selector">
                <select id="province" name="province" required>
                    <option value="">请选择省份</option>
                    <option value="beijing">北京市</option>
                    <option value="shanghai">上海市</option>
                    <option value="guangdong">广东省</option>
                    <option value="zhejiang">浙江省</option>
                </select>
                <select id="city" name="city" required>
                    <option value="">请选择城市</option>
                </select>
                <select id="district" name="district" required>
                    <option value="">请选择区县</option>
                </select>
            </div>
        </div>

        <div class="form-group required">
            <label for="address">详细地址</label>
            <input type="text" id="address" name="address" placeholder="请输入详细地址" required>
        </div>

        <div class="form-group required">
            <label for="model">设备型号</label>
            <select id="model" name="model" required>
                <option value="">请选择设备型号</option>
                <option value="model-a">型号A</option>
                <option value="model-b">型号B</option>
                <option value="model-c">型号C</option>
                <option value="model-d">型号D</option>
            </select>
        </div>

        <div class="form-group required">
            <label for="storageType">存储类型</label>
            <select id="storageType" name="storageType" required>
                <option value="">请选择存储类型</option>
                <option value="cold">冷藏</option>
                <option value="normal">常温</option>
                <option value="freeze">冷冻</option>
            </select>
        </div>

        <div class="form-group required">
            <label for="installDate">安装日期</label>
            <input type="date" id="installDate" name="installDate" required>
        </div>

        <div class="form-group required">
            <label for="mac">MAC地址</label>
            <input type="text" id="mac" name="mac" placeholder="请输入MAC地址" required minlength="10" maxlength="15">
        </div>

        <div class="btn-group">
            <button type="submit" class="btn btn-primary">确认</button>
            <button type="reset" class="btn btn-secondary">重置</button>
            <button type="button" class="btn btn-secondary" onclick="history.back()">取消</button>
        </div>
    </form>
</div>

<script>
    // 简单的地区联动示例
    document.getElementById('province').addEventListener('change', function() {
        const citySelect = document.getElementById('city');
        const districtSelect = document.getElementById('district');

        // 清空之前的选择
        citySelect.innerHTML = '<option value="">请选择城市</option>';
        districtSelect.innerHTML = '<option value="">请选择区县</option>';

        // 根据省份添加城市选项
        const province = this.value;
        if(province === 'beijing') {
            citySelect.innerHTML += '<option value="beijing">北京市</option>';
        } else if(province === 'shanghai') {
            citySelect.innerHTML += '<option value="shanghai">上海市</option>';
        } else if(province === 'guangdong') {
            citySelect.innerHTML += '<option value="guangzhou">广州市</option>';
            citySelect.innerHTML += '<option value="shenzhen">深圳市</option>';
        } else if(province === 'zhejiang') {
            citySelect.innerHTML += '<option value="hangzhou">杭州市</option>';
            citySelect.innerHTML += '<option value="ningbo">宁波市</option>';
        }
    });

    document.getElementById('city').addEventListener('change', function() {
        const districtSelect = document.getElementById('district');

        // 清空之前的选项
        districtSelect.innerHTML = '<option value="">请选择区县</option>';

        // 根据城市添加区县选项
        const city = this.value;
        if(city === 'beijing') {
            districtSelect.innerHTML += '<option value="dongcheng">东城区</option>';
            districtSelect.innerHTML += '<option value="xicheng">西城区</option>';
            districtSelect.innerHTML += '<option value="chaoyang">朝阳区</option>';
        } else if(city === 'shanghai') {
            districtSelect.innerHTML += '<option value="huangpu">黄浦区</option>';
            districtSelect.innerHTML += '<option value="jingan">静安区</option>';
            districtSelect.innerHTML += '<option value="xuhui">徐汇区</option>';
        } else if(city === 'guangzhou') {
            districtSelect.innerHTML += '<option value="yuexiu">越秀区</option>';
            districtSelect.innerHTML += '<option value="tianhe">天河区</option>';
        } else if(city === 'shenzhen') {
            districtSelect.innerHTML += '<option value="nanshan">南山区</option>';
            districtSelect.innerHTML += '<option value="futian">福田区</option>';
        } else if(city === 'hangzhou') {
            districtSelect.innerHTML += '<option value="xihu">西湖区</option>';
            districtSelect.innerHTML += '<option value="binjiang">滨江区</option>';
        } else if(city === 'ningbo') {
            districtSelect.innerHTML += '<option value="haishu">海曙区</option>';
            districtSelect.innerHTML += '<option value="jiangbei">江北区</option>';
        }
    });

    // 表单提交处理
    document.getElementById('cabinetForm').addEventListener('submit', function(e) {
        e.preventDefault();

        // 获取表单数据
        const formData = new FormData(this);
        const data = {};
        for (let [key, value] of formData.entries()) {
            data[key] = value;
        }

        // 简单验证
        if (!data.code || !data.province || !data.city || !data.district ||
            !data.address || !data.model || !data.storageType) {
            alert('请填写所有必填项');
            return;
        }

        // 在实际应用中，这里会发送数据到服务器
        console.log('提交的数据:', data);
        alert('柜机信息已提交');
    });
</script>
</body>
</html>
